package com.company.project.controller.goods;

import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;
import com.company.project.common.utils.DataResult;

import com.company.project.entity.SysGoodsAlbumEntity;
import com.company.project.service.SysGoodsAlbumService;



/**
 * 
 *
 * @author YangYulin
 * @email YangYulinit@163.com
 * @date 2020-08-05 16:20:50
 */
@Controller
@RequestMapping("/")
@Api(tags = "商品管理-商品相册")
public class SysGoodsAlbumController {
    @Autowired
    private SysGoodsAlbumService sysGoodsAlbumService;


    /**
    * 跳转到页面
    */
    @GetMapping("/index/sysGoodsAlbum")
    public String sysGoodsAlbum() {
        return "sysgoodsalbum/list";
        }

    @ApiOperation(value = "新增")
    @PostMapping("sysGoodsAlbum/add")
    @RequiresPermissions("sysGoodsAlbum:add")
    @ResponseBody
    public DataResult add(@RequestBody SysGoodsAlbumEntity sysGoodsAlbum){






        sysGoodsAlbumService.save(sysGoodsAlbum);
        return DataResult.success();
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("sysGoodsAlbum/delete")
    @RequiresPermissions("sysGoodsAlbum:delete")
    @ResponseBody
    public DataResult delete(@RequestBody @ApiParam(value = "id集合") List<String> ids){
        sysGoodsAlbumService.removeByIds(ids);
        return DataResult.success();
    }

    @ApiOperation(value = "更新")
    @PutMapping("sysGoodsAlbum/update")
    @RequiresPermissions("sysGoodsAlbum:update")
    @ResponseBody
    public DataResult update(@RequestBody SysGoodsAlbumEntity sysGoodsAlbum){
        sysGoodsAlbumService.updateById(sysGoodsAlbum);
        return DataResult.success();
    }

    @ApiOperation(value = "查询分页数据")
    @PostMapping("sysGoodsAlbum/listByPage")
    @RequiresPermissions("sysGoodsAlbum:list")
    @ResponseBody
    public DataResult findListByPage(@RequestBody SysGoodsAlbumEntity sysGoodsAlbum){
        Page page = new Page(sysGoodsAlbum.getPage(), sysGoodsAlbum.getLimit());
        QueryWrapper queryWrapper = new QueryWrapper();
        //查询条件示例
        //queryWrapper.eq("id", sysGoodsAlbum.getId());
        IPage<SysGoodsAlbumEntity> iPage = sysGoodsAlbumService.page(page, queryWrapper);
        return DataResult.success(iPage);
    }

}
